﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Tracy.DataModel;

namespace Tracy
{
    public class FeedSourceProvider
    {
        List<FeedSource> _feedSources = new List<FeedSource>();

        public List<FeedSource> FeedSources
        {
            get { return _feedSources; }
        }

        Dictionary<string, FeedSource> _indexName = new Dictionary<string, FeedSource>();
        public FeedSource GetItem(string name)
        {
            if(_indexName.ContainsKey(name))
                return _indexName[name];
            return null;
        }

        public FeedSourceProvider()
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(@"Settings\Sources.xml");
            foreach(XmlElement sourceNode in doc.SelectNodes("formats/format")){
                FeedSource source = new FeedSource(sourceNode);
                FeedSources.Add(source);
                _indexName.Add(source.Name, source);
            }
        }
    }
}
